package com.inspur.edp.ai.flow.core.engine.databus;

import com.inspur.edp.ai.flow.engine.DataBus;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lizhaorui
 * @date 2025/9/4
 * @description
 */
public class DefaultDataBus implements DataBus {

    private transient final Map<String, Object> dataMap = new ConcurrentHashMap<>();
    private String instanceId;

    public DefaultDataBus() {
        this.instanceId = UUID.randomUUID().toString();
    }

    public DefaultDataBus(String instanceId) {
        this.instanceId = instanceId;
    }

    public String getInstanceId() {
        return instanceId;
    }

    @Override
    public void put(String key, Object value) {
        if (value != null) {
            this.dataMap.put(key, value);
        }
    }

    @Override
    public Object get(String key) {
        return this.dataMap.get(key);
    }

    @Override
    public void remove(String key) {
        this.dataMap.remove(key);
    }

    @Override
    public Map<String, Object> getDataMap() {
        return this.dataMap;
    }
}
